#include <iostream>
#include<stdio.h>
using namespace std;


int main()
{
	//A 65
	int c, n, tmp;
	//cout << (char)(65+25);
	scanf("%d", &n);
	scanf("%d", &c);
	//cin >> n >> c;
	//cout << n << c;
	//cout << (char)((71 / 5) + 65)<<(71%5);
	int g, r;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &tmp);;
		r = tmp / c;
		g = tmp % c;
		if (g == 0)
		{
			printf("%c", (char)((r)+64));
			printf("%d", c);
			printf("%c", '\n');
			//cout << (char)((r)+64) << c;
			//cout << (char)A[tmp-1] << c <<endl;
		}
		else
		{
			printf("%c", (char)((r)+65));
			printf("%d", g);
			printf("%c", '\n');
			//cout << (char)((r)+65) << g << endl;
		}

	}

	//for (int i = 0; i < total; i++)
	//{
	//	cout << (char)A[i] << " ";
	//}
}
